package com.shntec.xtask.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;

import com.shntec.bp.common.BaseSQLHelper;
import com.shntec.bp.common.ShntecBaseDAO;
import com.shntec.bp.util.ShntecLogger;

public class XtaskTasksObject extends ShntecBaseDAO{
	
	private final static String THIS_TABLE_NAME = "xtask_tasks";
	private final static String THIS_PRIMARY_KEY_NAME = "tid";
	
	private Integer tid = null;
	private Integer aid = null;
	private Integer pid = null;
	private String tName = null;
	private String tDesc = null;
	private Integer status = null;
	private Integer fromTid = null;
	private Long createTime = null;
	private Integer forecast = null;
	private Long resumeTime = null;
	private Long pauseTime = null;
	private Long completeTime = null;
	private Integer theActual = null;
		
	public XtaskTasksObject(BaseSQLHelper helper){
		super(helper);
		tableName = THIS_TABLE_NAME;
		primaryKeyName = THIS_PRIMARY_KEY_NAME;
	}

	public Integer getTid() {
		return tid;
	}

	public void setTid(Integer tid) {
		this.tid = tid;
	}

	public Integer getAid() {
		return aid;
	}

	public void setAid(Integer aid) {
		this.aid = aid;
	}

	public Integer getPid() {
		return pid;
	}

	public void setPid(Integer pid) {
		this.pid = pid;
	}

	public String gettName() {
		return tName;
	}

	public void settName(String tName) {
		this.tName = tName;
	}

	public String gettDesc() {
		return tDesc;
	}

	public void settDesc(String tDesc) {
		this.tDesc = tDesc;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getFromTid() {
		return fromTid;
	}

	public void setFromTid(Integer fromTid) {
		this.fromTid = fromTid;
	}

	public Long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Long createTime) {
		this.createTime = createTime;
	}

	public Integer getForecast() {
		return forecast;
	}

	public void setForecast(Integer forecast) {
		this.forecast = forecast;
	}

	public Long getResumeTime() {
		return resumeTime;
	}

	public void setResumeTime(Long resumeTime) {
		this.resumeTime = resumeTime;
	}

	public Long getPauseTime() {
		return pauseTime;
	}

	public void setPauseTime(Long pauseTime) {
		this.pauseTime = pauseTime;
	}

	public Long getCompleteTime() {
		return completeTime;
	}

	public void setCompleteTime(Long completeTime) {
		this.completeTime = completeTime;
	}

	public Integer getTheActual() {
		return theActual;
	}

	public void setTheActual(Integer theActual) {
		this.theActual = theActual;
	}

	@Override
	protected boolean loadResultSet(ResultSet rs) {
		try {
			
			tid = rs.getInt("tid");
			aid = rs.getInt("aid");
			pid = rs.getInt("pid");
			tName = rs.getString("tname");
			tDesc = rs.getString("tdesc");
			status = rs.getInt("status");
			fromTid = rs.getInt("fromTid");
			createTime = rs.getLong("createTime");
			forecast = rs.getInt("forecast");
			resumeTime = rs.getLong("resumeTime");
			pauseTime = rs.getLong("pauseTime");
			completeTime = rs.getLong("completeTime");
			theActual = rs.getInt("theActual");

		} catch (SQLException e) {
			ShntecLogger.logger.error("Handle database resultset failed, table name=" + getTableName());
			ShntecLogger.logger.error(e.getMessage());
			return false;
		}
		
		return true;
	}

	@Override
	protected HashMap<String, Object> generateColumnList() {
		HashMap<String, Object> columnList = new HashMap<String, Object>();
		
		columnList.put("tid", tid);
		columnList.put("aid", aid);
		columnList.put("pid", pid);
		columnList.put("tname", tName);
		columnList.put("tdesc", tDesc);
		columnList.put("status", status);
		columnList.put("fromTid", fromTid);
		columnList.put("createtime", createTime);
		columnList.put("forecast", forecast);
		columnList.put("resumeTime", resumeTime);
		columnList.put("pauseTime", pauseTime);
		columnList.put("completeTime", completeTime);
		columnList.put("theActual", theActual);
		
		
		return columnList;
	}

	@Override
	protected void updateResultSet(ResultSet rs) throws SQLException {
		
		updateAllowNullColumns(rs, "aid", aid);

		updateAllowNullColumns(rs, "pid", pid);
		
		updateNotAllowNullColumns(rs, "tname", tName);
		
		updateNotAllowNullColumns(rs, "tdesc", tDesc);
		
		updateNotAllowNullColumns(rs,"status",status);
		
		updateNotAllowNullColumns(rs,"fromTid",fromTid);
		
		updateNotAllowNullColumns(rs, "createtime", createTime);
		
		updateNotAllowNullColumns(rs, "forecast", forecast);
		
		updateNotAllowNullColumns(rs, "resumeTime", resumeTime);
		
		updateNotAllowNullColumns(rs, "pauseTime", pauseTime);
		
		updateNotAllowNullColumns(rs, "completeTime", completeTime);
		
		updateNotAllowNullColumns(rs, "theActual", theActual);
		
	}
	
	
}
